{include mobile_template('header')}
<div class="panel-common">
	<form name="frm_recharge" action="{url pay/mobile/do/recharge/rand/$_G[random]}" method="POST">
		<div class="list-group list-group-insertmod">
			<div class="list-group-heading">在线充值</div>
			<div class="list-group-item">
				<div class="fr">
					<select name="pay[cztype]" id="pay_cztype">
						{if in_array('rmb', msm_pay_log::get_cz_type())}
						<option value="rmb" ratio="1" unit="元" selected="selected">现金</option>
						{/if}
						{print form_pay_groups($order['cztype'])}
					</select>
				</div>
				充值目标
			</div>
			<div class="list-group-item" id="ratio">
				<div class="fr">
					<span id="ratio_price">1</span> 元 = <span id="ratio_point">1 金币</span>
				</div>
				兑换比率
			</div>			
			<div class="list-group-item">
				<div class="fr">
					<input type="TEXT" name="pay[czprice]" id="pay_czprice" value="{print S('pay:czmin')}">
				</div>
				充值金额(元)
			</div>
			<div class="list-group-heading">支付方式</div>
			<div class="list-group-item" id="payment_rmb">
				<input type="hidden" name="payword" value="">
				<div class="fr">
					<input type="radio" name="payment" value="rmb">
				</div>
				账户余额
			</div>
			<!--{loop mc_pay::get_payments(true,'mobile') $payment}-->
			<div class="list-group-item">
				<div class="fr">
					<input type="radio" name="payment" value="{print $payment::flag_name()}" checked="checked">
				</div>
				{print $payment::$name}
			</div>
			<!--{/loop}-->
		</div>
		<div class="panel-body">
			<button type="submit" name="dosubmit" value="Y" class="btn btn-mycolor full-width">在线支付</button>
		</div>
	</form>
</div>
<div class="panel-comm panel-default none" id="enter_passwprd">
    <div class="panel-heading">余额支付</div>
    <div class="panel-body">
        <div class="form-box">
            <div class="form-item">
                <label for="">支付密码：</label>
                <input type="password" name="payword" value="">
            </div>
            <div class="form-error mb10">
                注意 : 未填写支付密码，如果您未设置支付密码，请先在“我的资料”页面设置支付密码。
            </div>
            <div class="form-submit">
                <div class="btn-group btn-group-auto">
                    <div class="btn-group">
                        <a class="btn btn-mycolor" href="javascript:" data-type="submit">充值</a>
                    </div>
                    <div class="btn-group">
                        <a class="btn btn-default" href="javascript:" data-type="close">取消</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
$(document).ready(function() {

	select_cztype($('#pay_cztype > option:selected'));

	$('#pay_cztype').change(function(event) {
		select_cztype($(this).find('option:selected'));
	});

	function select_cztype(option) {
		var type = option.val();
		if(type != 'rmb') {
			$('#ratio').show();
			$('#payment_rmb').show();
		} else {
			$('#ratio').hide();
			var payment_rmb = $('#payment_rmb');
			payment_rmb.hide();
			if(payment_rmb.find('input[type="radio"]').attr('checked')) {
				payment_rmb.find('input[type="radio"]').attr('checked', false);
				payment_rmb.next().find('input[type="radio"]').attr('checked', true);
			}
		}
		calc_ratio(option.attr('ratio'), option.text());
	}

	function calc_ratio(ratio,title) {
		var print = 1 * parseInt(ratio);
		var title = 
    		$('#ratio_point').text(print+ ' '+title);
	}

	var form = $('form[name="frm_recharge"]');
	//输入密码对话框
    var drawer = new $.m_drawer('#enter_passwprd', {type:'float-bottom'}, {
        onSubmit:function(container, workArea) {
            var payword = workArea.find('[name="payword"]').val().trim();
            if(payword=='') {
                alert('未填写支付密码，如果您未设置支付密码，请先在“我的资料”页面设置支付密码。');
                return;
            }
            form.find('input[name="payword"]').val(payword);
            //password
            form[0].submit();
        }
    });

    //表单提交
    form.submit(function(event) {
    		var pay_czprice = parseFloat($('#pay_czprice').val());
    		if($('input[name="payment"]:checked').val()=='rmb') {
    			//余额支付，显示输入密码对话框
    			drawer.open();
    			return false;
    		}
    });

});
</script>
{include mobile_template('footer')}